home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / RTF / debug.h next >
C/C++ Source or Header  |  1994-08-01  |  1KB  |  53 lines

  1. /* debug.h -- Connolly's debugging junk
  2.  * 7 Jun 90 by Connolly 
  3.  * $Header: /usr/people/pcd/Src/RTF/RCS/debug.h,v 1.1 92/11/23 12:58:50 pcd Exp Locker: pcd $
  4.  * 
  5.  *
  6.  * USE: debug(("debugging message", printf, args))
  7.  * just like you would printf, but with extra ().
  8.  * They disappear at compile time if DEBUG is not 1.
  9.  */
  10.  
  11. #define DEBUG_DEFAULT 0
  12.  
  13. #ifndef DEBUG
  14. #define DEBUG DEBUG_DEFAULT
  15. #endif
  16.  
  17. #if DEBUG
  18. #  include <stdio.h>
  19. #  define debug(x) printf x
  20. #  define Debug(s, x) ((debug_##s) ?  printf x : 0)
  21. #else
  22. #  define debug(x) do{}while(0)
  23. #  define Debug(s, x) do{}while(0)
  24. #endif
  25.  
  26. /*
  27.  * REQUIRE(condition, stmnt_if_fail)
  28.  * be sure to free dynamic memory on failure.
  29.  * e.g.
  30.  * p = malloc(size);
  31.  * REQUIRE(x>0, return (free(p), -1));
  32.  */
  33. #define REQUIRE(x,return_y)                   \
  34.   if(!(x)){                                   \
  35.     debug(("requirement failed: %s\n", #x));  \
  36.     return_y;                                 \
  37.   }
  38.  
  39. #define TIMING_DEFAULT 0
  40.  
  41. #ifndef TIMING
  42. #define TIMING TIMING_DEFAULT
  43. #endif
  44.  
  45. #if TIMING
  46. extern "C" clock(void);
  47. #define timing(s) printf("<%s>clock = %d\n", s, clock())
  48. #else
  49. #define timing(s) do{}while(0)
  50. #endif
  51.  
  52.  
  53.